package com.hs.jpademo1.controller;

import com.hs.jpademo1.annotation.MyLog;
import com.hs.jpademo1.entity.Student;
import com.hs.jpademo1.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName StudentController
 * @Description TODO
 * @Author 郭敖
 * @Date 2023年08月15日 20:11
 * @Version 1.0
 */

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService service;

    @PutMapping
    public String update(@RequestBody Student student){
        try {
            int i = service.updateStudent(student);
        }catch (RuntimeException e){
            e.printStackTrace();
            return e.getMessage();
        }
        return "更新成功!!";
    }

    @PostMapping
    public String addStudent(@RequestBody Student student) {
        try{
            int i = service.addStudent(student);
        }catch (RuntimeException e){
            return e.getMessage();
        }
        return "success";
    }

    @GetMapping("/getAll")
    @MyLog("getAll")
    public String getAll(){
        return "getAll";
    }
}
